const router = require('koa-router')()
const koa2Req = require('koa2-request');
const axios = require("axios");
const {
  login,
  getImages,
  getServers,
  getNetworks,
  deleteImage,
  createImage,
  connectVNC
} = require('../http/api')
const fs = require('fs')
const {
  createFirstMenu,
  createSecondMenu,
  createPage
} = require('../utils/menu')
const {
  respondTableOk,
  respondOk
} = require('../utils/responseTemplate')
const Qs = require("qs"); //qs是一个url参数转化（parse/stringify）的js库


router.prefix('/cloudtest/api/v2')
let token = fs.readFileSync('./cache', 'utf-8') || null

// router.option('/sys/login', async function (ctx,next){

// })
/**
 * 登录接口
 */
router.post('/sys/login', async function (ctx, next) {
  const params = ctx.request.body
  console.log('params', params);
  const data = await login(params)
  token = data.access_token
  fs.writeFileSync('./cache', token)
  ctx.body = {
    code: 200,
    result: {
      token: data.access_token,
      userInfo: {
        username: data.user.username
      }
    }
  }
})


/**
 * 获取权限接口
 */
router.get('/sys/permission/getUserPermissionByToken', function (ctx, next) {
  ctx.body = {
    "success": true,
    "message": "查询成功",
    "code": 200,
    "result": {
      "allAuth": [{
        "action": "online:goGenerateCode",
        "describe": "代码生成按钮",
        "type": "1",
        "status": "1"
      }, {
        "action": "user:add",
        "describe": "添加按钮",
        "type": "1",
        "status": "1"
      }, {
        "action": "user:edit",
        "describe": "用户编辑",
        "type": "1",
        "status": "1"
      }, {
        "action": "user:sex",
        "describe": "表单性别可见",
        "type": "1",
        "status": "1"
      }, {
        "action": "user:form:birthday",
        "describe": "禁用生日字段",
        "type": "2",
        "status": "1"
      }, {
        "action": "user:form:phone",
        "describe": "手机号禁用",
        "type": "2",
        "status": "1"
      }],
      "auth": [{
        "action": "online:goGenerateCode",
        "describe": "代码生成按钮",
        "type": "1"
      }, {
        "action": "user:add",
        "describe": "添加按钮",
        "type": "1"
      }],
      "menu": [
        // 设置一级菜单
        // createFirstMenu('首页', "/dashboard/analysis", "dashboard/Analysis"),
        createFirstMenu('首页', "home/home", "home/Home"),
        createFirstMenu('项目管理', "project-list", "projectList/ProjectList", 'project'),
        // 设置二级菜单
        createSecondMenu('环境管理', [{
          name: '环境柔性构建',
          path: 'create-env',
          component: 'createEnv/CreateEnv'
        },
        {
          name: '环境自定义构建',
          path: 'custom-env',
          component: 'customEnv/CustomEnv'
        }, {
          name: '虚拟机管理',
          path: 'vm-list',
          component: 'vmList/VmList'
        },
        {
          name: '网络管理',
          path: 'network-list',
          component: 'network/NetworkList'
        },
        {
          name: '路由管理',
          path: 'router-list',
          component: 'router/RouterList'
        },

        ], 'windows'),
        // 设置一级菜单
        createFirstMenu('任务管理', "task-list", "taskList/TaskList", 'container'),
        createFirstMenu('用户管理', "user-list", "userList/UserList", 'user'),
        createFirstMenu('镜像管理', "/imagelist/imagelist", "imagelist/ImageList", 'cloud-server'),
        createFirstMenu('测试工具管理', "tool-list", "toolList/ToolList", 'tool'),
        createFirstMenu('角色管理', "role-list", "roles/roles", 'team'),
        // createFirstMenu('虚拟机管理', "/servers/serverlist", "servers/ServersList"),
        // createFirstMenu('网络管理', "/network/networklist", "network/NetworkList"),
        // createFirstMenu('路由管理', "/router/routerlist", "router/RouterList"),
        // createFirstMenu('项目详情', "project-detail", "projectDetail/ProjectDetail"),
        // createFirstMenu('配置项目环境', "create-env", "createEnv/CreateEnv"),

        {
          "redirect": null,
          "path": "/projects",
          "component": "layouts/RouteView",
          "route": "1",
          "hidden": true,
          "children": [
            // 设置普通页面
            createPage('项目详情', "project-detail", "projectDetail/ProjectDetail"),
            createPage('配置环境', "create-env", "createEnv/CreateEnv"),
            createPage('项目成员', "project-members", "projectMembers/ProjectMembers"),
            createPage('虚拟机详情', "vm-detail", "vmDetail/VmDetail"),
          ],
          "meta": {
            "keepAlive": false,
            "internalOrExternal": false,
            "icon": "user",
            "componentName": "RouteView",
            "title": "个人页"
          },
          "name": "account",
          "id": "717f6bee46f44a3897eca9abd6e2ec44"
        },
      ]
    },
    "timestamp": 1624330126166
  }
})

/**
 * 查询项目列表
 */
router.get('/projects', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  // 0 未开始 UNSTART
  // 1 进行中 ACTIVE
  // 2 已结项 FINISHED
  // 3 已延期 TIMEOUT
  const result = [{
    "id": "1423423642342",
    "name": "项目1",
    "description": "",
    "status": "UNSTART",
    "startTime": "2014-11-10",
    "endTime": "2014-11-20",
    "quotaId": "12343242343432"
  },
  {
    "id": "2423412342342",
    "name": "项目2",
    "description": "项目2项目2项目2项目2",
    "status": "ACTIVE",
    "startTime": "2014-11-09",
    "endTime": "2014-11-27",
    "quotaId": "12343242343432"
  },
  {
    "id": "3423423242342",
    "name": "项目1",
    "description": "项目1项目1项目1项目1",
    "status": "FINISHED",
    "startTime": "2014-11-10",
    "endTime": "2014-11-20",
    "quotaId": "12343242343432"
  },
  {
    "id": "423423429342",
    "name": "项目4",
    "description": "项目4项目4项目4项目4项目4",
    "status": "TIMEOUT",
    "startTime": "2014-11-09",
    "endTime": "2014-11-27",
    "quotaId": "24234236422342"
  },
  ]
  ctx.body = respondOk(result)
})


/**
 * 查询项目配额
 */
router.get('/projects/quota', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [{
    "id": "12343242343432",
    "name": "标准配额",
    "source": {
      "calculate": {
        "serverTotal": 10,
        "cpuTotal": 30,
        "ramTotal": 30,
      },
      "volume": {
        "diskTotal": 30,
        "diskSize": 30,
      },
      "network": {
        "networkTotal": 30,
        "portTotal": 30,
        "routerTotal": 30,
      }
    },
  },
  {
    "id": "24234236422342",
    "name": "高级配额",
    "source": {
      "calculate": {
        "serverTotal": 110,
        "cpuTotal": 130,
        "ramTotal": 130,
      },
      "volume": {
        "diskTotal": 130,
        "diskSize": 130,
      },
      "network": {
        "networkTotal": 130,
        "portTotal": 130,
        "routerTotal": 130,
      }
    },
  }
  ]
  ctx.body = respondOk(result)
})



/**
 * 新建项目
 */
router.post('/projects', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = {}
  ctx.body = respondOk(data)
})

/**
 * 修改项目信息
 */
router.put('/projects', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = {
    "id": "42342342342",
    "name": "xiezh",
    "description": "xxxxxxxxxxxxx",
    "status": "UNSTART",
    "startTime": "234234234234",
    "endTime": "3423423423"
  }
  ctx.body = respondOk(data)
})

/**
 * 结束项目
 */
router.patch('/projects', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = {
    "id": "42342342342",
    "name": "xiezh",
    "description": "xxxxxxxxxxxxx",
    "status": "UNSTART",
    "startTime": "234234234234",
    "endTime": "3423423423"
  }
  ctx.body = respondOk(data)
})

/**
 * 删除项目
 */
router.delete('/projects', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  ctx.body = respondOk(null)
})

/**
 * 删除批量项目
 */
router.delete('/projects/deleteBatch', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  ctx.body = respondOk(null)
})



/**
 * 项目详情
 */
router.get('/projects/detail', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = {
    "name": "xiezh",
    "description": "xxxxxxxxxxxxxx",
    "startTime": "2021-07-01",
    "endTime": "2021-07-01",
    "source": {
      "calculate": {
        "serverTotal": 10,
        "usedServer": 1,
        "cpuTotal": 30,
        "usedCpu": 2,
        "ramTotal": 30,
        "usedRam": 2
      },
      "volume": {
        "diskTotal": 30,
        "usedDisk": 2,
        "diskSize": 30,
        "usedDiskSize": 2
      },
      "network": {
        "networkTotal": 30,
        "usedNetwork": 2,
        "portTotal": 30,
        "usedPort": 2,
        "routerTotal": 30,
        "usedRouter": 2
      }
    },
    "taskList": [{
      "id": "32423423423",
      "version": "1.0",
    },
    {
      "id": "32423423423",
      "version": "2.0",
    },
    {
      "id": "32423423423",
      "version": "3.0",
    },
    ]
  }
  ctx.body = respondOk(result)
})


/**
 * 测试工具管理
 */
router.get('/tools', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [
    {
      "id": "234234234",
      "name": "postman",
      "description": "接口测试工具",
      "size": "24Mb",
      "size": "24Mb",
      "projectName": "云测项目",
      "creator": "赵四",
      "createTime": "2021-11-12 21：12：21",
    },
    {
      "id": "234234234",
      "name": "postman",
      "description": "接口测试工具",
      "size": "24Mb",
      "size": "24Mb",
      "projectName": "云测项目",
      "creator": "赵四",
      "createTime": "2021-11-12 21：12：21",
    },
    {
      "id": "234234234",
      "name": "postman",
      "description": "接口测试工具",
      "size": "24Mb",
      "size": "24Mb",
      "projectName": "云测项目",
      "creator": "赵四",
      "createTime": "2021-11-12 21：12：21",
    }
  ]
  ctx.body = respondOk(result)
})


/**
 * 查询测试环境
 */
router.get('/vm', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  //   虚拟机状态
  //   构建中 BUILD
  // 已关闭电源  SHUTOFF
  // 运行中  ACTIVE
  // 硬重启 HARD_REBOOT 
  // 软重启  REBOOT
  // 构建失败  FAILED

  const result = [{
    "id": "134234234234",
    "name": "xiezh0011",
    "status": "BUILD",
    "fixedIp": "192.168.2.110",
    "floatIp": "110.110.2.110",
    "flavor": {
      "cpu": 2,
      "ram": 1024,
      "disk": 256
    },
    "imageName": "win10",
    "projectName": "xxxxx项目1",
    "projectId": "123432432"
  },
  {
    "id": "234233234234",
    "name": "xiezh001",
    "status": "SHUTOFF",
    "fixedIp": "192.168.2.110",
    "floatIp": "110.110.2.110",
    "flavor": {
      "cpu": 2,
      "ram": 2048,
      "disk": 256
    },
    "imageName": "win10",
    "projectName": "xxxxx项目2",
    "projectId": "2123432432"
  },
  {
    "id": "34234234254",
    "name": "xiezh001",
    "status": "ACTIVE",
    "fixedIp": "192.168.2.110",
    "floatIp": "110.110.2.110",
    "flavor": {
      "cpu": 2,
      "ram": 2048,
      "disk": 256
    },
    "imageName": "win10",
    "projectName": "xxxxx项目2",
    "projectId": "2123432432"
  },
  {
    "id": "44234234254",
    "name": "xiezh001",
    "status": "HARD_REBOOT",
    "fixedIp": "192.168.2.110",
    "floatIp": "110.110.2.110",
    "flavor": {
      "cpu": 2,
      "ram": 2048,
      "disk": 256
    },
    "imageName": "win10",
    "projectName": "xxxxx项目2",
    "projectId": "2123432432"
  },
  {
    "id": "54234234254",
    "name": "xiezh005",
    "status": "FAILED",
    "fixedIp": "192.168.2.110",
    "floatIp": "110.110.2.110",
    "flavor": {
      "cpu": 2,
      "ram": 2048,
      "disk": 256
    },
    "imageName": "win10",
    "projectName": "xxxxx项目2",
    "projectId": "2123432432"
  },
  {
    "id": "64234234254",
    "name": "xiezh001",
    "status": "REBOOT",
    "fixedIp": "192.168.2.110",
    "floatIp": "110.110.2.110",
    "flavor": {
      "cpu": 2,
      "ram": 2048,
      "disk": 256
    },
    "imageName": "win10",
    "projectName": "xxxxx项目2",
    "projectId": "2123432432"
  }
  ]
  ctx.body = respondOk(result)
})


/**
 * 查询网络列表
 */
router.get('/networks', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);

  const result = [
    {
      "id": "34234234234",
      "name": "xiezh-netword-001",
      "sub": "192.1.0.0/16 10.1.0.0/16",
      "share": "No",
      "public": "No",
      "status": "ACTIVE",
    },
    {
      "id": "34234234234",
      "name": "xiezh-netword-001",
      "sub": "192.1.0.0/16 10.1.0.0/16",
      "share": "No",
      "public": "No",
      "status": "ACTIVE",
    },
    {
      "id": "34234234234",
      "name": "xiezh-netword-001",
      "sub": "192.1.0.0/16 10.1.0.0/16",
      "share": "No",
      "public": "No",
      "status": "ACTIVE",
    },
  ]
  ctx.body = respondOk(result)
})

/**
 * 查询路由列表
 */
router.get('/routers', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);

  const result = [
    {
      "id": "34234234234",
      "name": "xiezh-netword-001",
      "share": "No",
      "public": "public-network",
      "status": "ACTIVE",
    },
    {
      "id": "34234234234",
      "name": "xiezh-netword-001",
      "share": "No",
      "public": "public-network",
      "status": "ACTIVE",
    },
    {
      "id": "34234234234",
      "name": "xiezh-netword-001",
      "share": "No",
      "public": "public-network",
      "status": "ACTIVE",
    },
  ]
  ctx.body = respondOk(result)
})
/**
 * 获取推荐配置
 */
router.post('/vm/recommend', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = {
    "recommend": [
      {
        "flavor": {
          "id": "34324234",
          "cpu": 1,
          "ram": 2,
          "disk": 256,
        },
        "imageId": "23423423423",
        "imageName": "win10",
        "number": 5,
        // 新增加“静态分析”、“功能测试”、“性能测试”、“安全测试”
        "tools": {
          "static": [
            "testbed",
            "coverity",
            "sqa-cobot"
          ],
          "function": [
            "hp-uft",
            "sqa-at",
            "Selenium"
          ],
          "performance": [
            "loadrunner",
            "jmeter"
          ],
          "safety": [
            "xxxx",
            "xxxx"
          ]
        }
      },
      {
        "flavor": {
          "id": "34324234",
          "cpu": 2,
          "ram": 2,
          "disk": 256,
        },
        "imageId": "23423423423",
        "imageName": "win10",
        "number": 5,
        "tools": {
          "static": [
            "testbed",
            "coverity",
            "sqa-cobot"
          ],
          "function": [
            "hp-uft",
            "sqa-at",
            "Selenium"
          ],
          "performance": [
            "loadrunner",
            "jmeter"
          ],
          "safety": [
            "xxxx",
            "xxxx"
          ]
        }
      },
      {
        "flavor": {
          "id": "34324234",
          "cpu": 3,
          "ram": 2,
          "disk": 256,
        },
        "imageId": "23423423423",
        "imageName": "win10",
        "number": 5,
        "tools": {
          "static": [
            "testbed",
            "coverity",
            "sqa-cobot"
          ],
          "function": [
            "hp-uft",
            "sqa-at",
            "Selenium"
          ],
          "performance": [
            "loadrunner",
            "jmeter"
          ],
          "safety": [
            "xxxx",
            "xxxx"
          ]
        }
      },
    ],
    "dynamic": [
      {
        "flavor": {
          "cpu": 2,
          "ram": 2,
          "disk": 256,
        },
        "imageId": "23423423423",
        "imageName": "win10",
        "number": 5,
        "tools": {
          "static": [
            "testbed",
            "coverity",
            "sqa-cobot"
          ],
          "function": [
            "hp-uft",
            "sqa-at",
            "Selenium"
          ],
          "performance": [
            "loadrunner",
            "jmeter"
          ],
          "safety": [
            "xxxx",
            "xxxx"
          ]
        }
      },
      {
        "flavor": {
          "cpu": 2,
          "ram": 2,
          "disk": 256,
        },
        "imageId": "23423423423",
        "imageName": "win10",
        "number": 5,
        "tools": {
          "static": [
            "testbed",
            "coverity",
            "sqa-cobot"
          ],
          "function": [
            "hp-uft",
            "sqa-at",
            "Selenium"
          ],
          "performance": [
            "loadrunner",
            "jmeter"
          ],
          "safety": [
            "xxxx",
            "xxxx"
          ]
        }
      },
      {
        "flavor": {
          "cpu": 2,
          "ram": 2,
          "disk": 256,
        },
        "imageId": "23423423423",
        "imageName": "win10",
        "number": 5,
        "tools": {
          "static": [
            "testbed",
            "coverity",
            "sqa-cobot"
          ],
          "function": [
            "hp-uft",
            "sqa-at",
            "Selenium"
          ],
          "performance": [
            "loadrunner",
            "jmeter"
          ],
          "safety": [
            "xxxx",
            "xxxx"
          ]
        }
      },
    ],
    "custom": [{
      "id": "234123423423",
      "name": "两个子网互联",
      "description": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    {
      "id": "234233423423",
      "name": "两个子网互联",
      "description": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    {
      "id": "234235423423",
      "name": "两个子网互联",
      "description": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }
    ]
  }
  ctx.body = respondOk(data)
})


/**
 * 查询镜像列表
 */
router.get('/images', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [{
    "id": "234237234234",
    "name": "win10",
  },
  {
    "id": "234234234834",
    "name": "CentOS7"
  },
  {
    "id": "234234234224",
    "name": "Ubuntu16.04"
  }
  ]
  ctx.body = respondOk(result)
})
/**
 * 查询镜像详情列表
 */
router.get('/images/list', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [
    {
      "id": "234237234234",
      "name": "win10",
      "owner": "bjtest",
      "status": "ACTIVE",
      "description": "xxxxxx",
      "visible": false,
      "property": true,
      "diskFormat": "qcow2",
      "size": "21341Mb",
      "createTime": "2021-07-07 09:23:03"
    },
    {
      "id": "234237234234",
      "name": "win10",
      "owner": "bjtest",
      "status": "ACTIVE",
      "description": "xxxxxx",
      "visible": false,
      "property": true,
      "diskFormat": "qcow2",
      "size": "21341Mb",
      "createTime": "2021-07-07 09:23:03"
    },
    {
      "id": "234237234234",
      "name": "win10",
      "owner": "bjtest",
      "status": "ACTIVE",
      "description": "xxxxxx",
      "visible": false,
      "property": true,
      "diskFormat": "qcow2",
      "size": "21341Mb",
      "createTime": "2021-07-07 09:23:03"
    },
    {
      "id": "234237234234",
      "name": "win10",
      "owner": "bjtest",
      "status": "ACTIVE",
      "description": "xxxxxx",
      "visible": false,
      "property": true,
      "diskFormat": "qcow2",
      "size": "21341Mb",
      "createTime": "2021-07-07 09:23:03"
    },
  ]
  ctx.body = respondOk(result)
})


/**
 * 创建虚拟机
 */
router.post('/vm/create', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  // E6005 资源配置不足
  const data = null
  ctx.body = respondOk(data)
})

/**
 * 创建自定义环境
 */
router.post('/vm/env', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = {
    "id": "23423423",
    "name": "xiezh",
    "description": "xxxxxxxxxxxxxxxxxxxxxx",
    "template": {}
  }
  ctx.body = respondOk(data)
})


/**
 * 虚拟机操作
 * REBOOT 重启； SHUTDOWN 关机； BOOTUP 开机； 
 */
router.put('/vm/operation', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = null
  ctx.body = respondOk(data)
})


/**
 * 虚拟机重命名
 */
router.put('/vm/rename', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = null
  ctx.body = respondOk(data)
})


/**
 * 虚拟机重置密码
 */
router.put('/vm/password', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  const data = null
  ctx.body = respondOk(data)
})


/**
 * 虚拟机远程连接
 */
router.get('/vm/connection', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = {
    url: "https://www.baidu.com"
  }
  ctx.body = respondOk(result)
})


/**
 * 虚拟机详情
 */
router.get('/vm/detail', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  // 虚拟机状态
  // 构建中 BUILD 已关闭电源  SHUTOFF 运行中  ACTIVE 硬重启 HARD_REBOOT  软重启  REBOOT 构建失败 FAILED
  const result = {
    vm: {
      id: "34324234",
      name: "host0001",
      status: "ACTIVE",
      createTime: "2021-07-15 15：12：22",
    },
    network: {
      name: "network001",
      fixedIp: "192.168.2.110",
      mac: "1e:1e:1e:1e:1e:1e"
    },
    image: {
      name: "win10",
      id: "234324233423",
    },
    flavor: {
      cpu: 2,
      ram: 2342,
      disk: 2
    }
  }
  ctx.body = respondOk(result)
})


/**
 * 查询成员列表
 */
router.get('/projects/members', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  // 1 男 MALE
  // 0 女 FEMALE
  const result = [{
    "id": "234234324234",
    "name": "成员1",
    "gender": "MALE",
    "phone": "18810447748",
    "roles": [{
      "id": "3423423423",
      "name": "测试员"
    },
    {
      "id": "3423423423",
      "name": "文档管理员"
    }

    ],
    "department": "中认-研发中心"
  },
  {
    "id": "234234324234",
    "name": "成员2",
    "gender": "MALE",
    "phone": "18810447748",
    "roles": [{
      "id": "3423423423",
      "name": "测试员"
    },
    {
      "id": "3423423423",
      "name": "文档管理员"
    }

    ],
    "department": "中认-研发中心"
  },
  {
    "id": "234234324234",
    "name": "xiezh03",
    "gender": "FEMALE",
    "phone": "18810447748",
    "roles": [{
      "id": "3423423423",
      "name": "测试员"
    },
    {
      "id": "3423423423",
      "name": "文档管理员"
    }

    ],
    "department": "中认-研发中心"
  }
  ]
  ctx.body = respondOk(result)
})


/**
 * 查询用户列表
 */
router.get('/users', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [{
    "id": "234234234234",
    "name": "xiezh"
  },
  {
    "id": "2342342224234",
    "name": "xiezh002"
  },
  {
    "id": "23423423214234",
    "name": "xiezh003"
  }
  ]
  ctx.body = respondOk(result)
})

/**
 * 删除项目成员
 */
router.delete('/projects/member', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  ctx.body = respondOk()
})

/**
 * 删除批量项目成员
 */
router.delete('/projects/members', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  ctx.body = respondOk()
})

/**
 * 授权
 */
router.put('/projects/members/permission', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk()
})

/**
 * 添加项目成员
 */
router.post('/projects/members', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk(null)
})


/**
 * 角色列表
 */
router.get('/roles', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [{
    "id": "234235423423",
    "name": "管理员1",
    "description": "管理员1管理员1管理员1管理员1管理员1"
  },
  {
    "id": "2342347223423",
    "name": "管理员2",
    "description": "管理员2管理员2管理员2管理员2"
  },
  {
    "id": "2342344323423",
    "name": "管理员3",
    "description": "管理员3管理员3管理员3"
  }
  ]
  ctx.body = respondOk(result)
})


/**
 * 角色删除
 */
router.delete('/roles', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = null
  ctx.body = respondOk(result)
})




/**
 * 查询被测件列表
 */
router.get('/projects/duts', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [{
    "id": "23423423423",
    "name": "被测件01",
    "size": "500Mb",
    "version": "1.0",
    "remark": "xxxxxxxxxxxxxxxx",
    "createTime": "2021-6-8 20:21:23"
  },
  {
    "id": "23423423423",
    "name": "被测件02",
    "size": "500Mb",
    "version": "1.0",
    "remark": "xxxxxxxxxxxxxxxx",
    "createTime": "2021-6-8 20:21:23"
  }, {
    "id": "23423423423",
    "name": "被测件03",
    "size": "500Mb",
    "version": "1.0",
    "remark": "xxxxxxxxxxxxxxxx",
    "createTime": "2021-6-8 20:21:23"
  }
  ]
  ctx.body = respondOk(result)
})

/**
 * 上传被测件
 */
router.post('/projects/duts', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk()
})

/**
 * 查询测试任务
 */
router.get('/projects/task', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  //   status 状态
  // 0 待测试  UNSTART
  // 1 待测试  UNSTART
  // 2 测试异常 ERROR
  const data = {
    "id": "32423423423",
    "name": "测试用例1",
    "startTime": "2021-07-01",
    "endTime": "2021-07-10",
    "description": "xxxxxxxxxxxxxxxxxx",
    "version": "3.0",
    "caseList": [{
      "id": "23423423423423",
      "code": "kb001",
      "name": "登录操作",
      "status": "UNSTART",
      "description": "xxxxxxxxxxxxx"
    },
    {
      "id": "234234223423423",
      "code": "kb001",
      "name": "登录操作02",
      "status": "PASS",
      "description": "xxxxxxxxxxxxx"
    },
    {
      "id": "234234234233423",
      "code": "kb001",
      "name": "登录操作03",
      "status": "ERROR",
      "description": "xxxxxxxxxxxxx"
    }
    ]

  }
  ctx.body = respondOk(data)
})


/**
 * 测试用例列表
 * 
 */
router.get('/cases', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  //   status 状态
  // 0 待测试  UNSTART
  // 1 待测试  UNSTART
  // 2 测试异常 ERROR
  const data = [
    {
      "id": "23423423423423",
      "code": "kb001",
      "name": "登录操作",
      "status": "UNSTART",
      "description": "xxxxxxxxxxxxx",
      "projectName": "test",
      "version": '1.0'
    },
    {
      "id": "23423423423423",
      "code": "kb001",
      "name": "登录操作",
      "status": "UNSTART",
      "description": "xxxxxxxxxxxxx",
      "projectName": "test",
      "version": '1.0'
    },
    {
      "id": "23423423423423",
      "code": "kb001",
      "name": "登录操作",
      "status": "UNSTART",
      "description": "xxxxxxxxxxxxx",
      "projectName": "test",
      "version": '1.0'
    },
    {
      "id": "23423423423423",
      "code": "kb001",
      "name": "登录操作",
      "status": "UNSTART",
      "description": "xxxxxxxxxxxxx",
      "projectName": "test",
      "version": '1.0'
    },
  ]
  ctx.body = respondOk(data)
})

/**
 * 添加测试用例
 */
router.post('/projects/tasks/case', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk(null)
})


/**
 * 提交测试记录
 */
router.post('/projects/tasks/case/record', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk(null)
})



/**
 * 测试任务迭代
 */
router.post('/projects/tasks/iteration', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk(null)
})


/**
 * 测试用例详情
 */
router.get('/projects/tasks/cases/detail', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  //   用例状态
  // PASS 通过
  // ERROR 异常

  const result = {
    "id": "23432423423",
    "name": "登录操作",
    "code": "kj0001",
    "description": "xxxxxxxxxxxxxxxx",
    "records": [{
      "sketch": 'xxxxxx',
      "description": "xxxxxxxxxxxxxxxx",
      "status": "PASS",
      "creator": "王鹏",
      "createTime": "2021-10-11 20:21:11"
    },
    {
      "sketch": 'x02xxxxx',
      "description": "xxxx02xxxxxxxxxxxx",
      "status": "ERROR",
      "creator": "王鹏02",
      "createTime": "2021-10-11 20:21:11"
    },
    {
      "sketch": 'xxx03xxx',
      "description": "xxxxx03xxxxxxxxxxx",
      "status": "PASS",
      "creator": "王鹏03",
      "createTime": "2021-10-11 20:21:11"
    }
    ]
  }
  ctx.body = respondOk(result)
})


/**
 * 首页
 */
router.get('/home', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  //   项目状态映射
  // 0 未开始 UNSTART
  // 1 进行中 ACTIVE
  // 2 已结项 FINISHED
  // 3 已延期 TIMEOUT
  const result = {
    "projectTotal": 10,
    "unstartProjects": 3,
    "unfinishedProjects": 3,
    "deferredProjects": 1,
    "caseTotal": 100,
    "unstartCase": 10,
    "projects": [{
      "id": "342342342343",
      "name": "项目1",
      "status": "UNSTART",
      "description": "项目1项目1项目1项目1项目1项目1",
      "startTime": "2014-01-10",
      "endTime": "2014-12-13",
    },
    {
      "id": "3423142342343",
      "name": "项目2",
      "status": "ACTIVE",
      "description": "项目1项目1项目1项目1项目1",
      "startTime": "2014-01-10",
      "endTime": "2014-09-13",
    },
    {
      "id": "3423242342343",
      "name": "项目3",
      "status": "FINISHED",
      "description": "项目3项目3项目3项目3项目3项目3",
      "startTime": "2014-10-10",
      "endTime": "2014-11-01",
    },
    {
      "id": "3423242342343",
      "name": "项目4",
      "status": "TIMEOUT",
      "description": "项目4项目4项目4项目4项目4",
      "startTime": "2014-11-10",
      "endTime": "2014-11-13",
    }
    ],
    "cases": [{
      "id": "2342342334234",
      "sketch": "用例1",
      "status": "UNSTART",
      "description": "用例1用例1用例1用例1用例1"
    },
    {
      "id": "2342314234234",
      "sketch": "用例2",
      "status": "ERROR",
      "description": "用例2用例2用例2用例2用例2用例2"
    },
    {
      "id": "2342346234234",
      "sketch": "用例3",
      "status": "PASS",
      "description": "用例3用例3用例3用例3用例3"
    }
    ]
  }
  ctx.body = respondOk(result)
})

/**
 * 角色修改
 */
router.put('/roles', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk(null)
})

/**
 * 角色授权
 */
router.put('/roles/permission', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk(null)
})


/**
 * 权限列表
 */
router.get('/roles/permissions', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = [{
    "id": "234234234",
    "name": "xxx01"
  },
  {
    "id": "234234234",
    "name": "xxx02"
  },
  {
    "id": "234234234",
    "name": "xxx03"
  },
  {
    "id": "234234234",
    "name": "xxx04"
  }
  ]
  ctx.body = respondOk(result)
})

/**
 * get
 */
router.get('/ro', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  const result = {}
  ctx.body = respondOk(result)
})

/**
 * delete
 */
router.delete('/projects', async function (ctx, next) {
  const query = ctx.request.query
  console.log('参数：', query);
  ctx.body = respondOk()
})

/**
 * put
 */
router.put('/projects/status', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk()
})

/**
 * post
 */
router.post('/projects/create', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk()
})

/**
 * post
 */
router.patch('/projects/create', async function (ctx, next) {
  const body = ctx.request.body
  console.log('参数：', body);
  ctx.body = respondOk()
})

module.exports = router